import React, { Component } from "react";
import { View, Text, FlatList } from "react-native";
import CustomHeader from "../../components/CustomHeader";
import { ListItem } from "react-native-elements";
import { request } from "../../utils";
import moment from "moment";

class AllRecord extends Component {
  constructor(props) {
    super(props);
    this.state = {
      pId: props.navigation.getParam("pId", 0),
      pName: props.navigation.getParam("pName"),
      recordList: ""
    };
  }

  componentDidMount() {
    const { pId } = this.state;
    request("record/list", { id: pId }, recordList =>
      this.setState({ recordList })
    );
  }

  render() {
    const { pName, recordList } = this.state;
    return (
      <View>
        <CustomHeader title={pName + "-全部记录"} />
        <FlatList
          data={recordList}
          renderItem={({ item }) => {
            return (
              <ListItem
                title={item.RType}
                subtitle={item.Remark}
                rightTitle={moment(item.RecordTime).format("YYYY-MM-DD HH:mm")}
                rightTitleStyle={{
                  width: 200,
                  textAlign: "right"
                }}
                bottomDivider
              />
            );
          }}
        />
      </View>
    );
  }
}

export default AllRecord;
